var user_setting_ops={
    init:function(){
        this.eventBind();
    },
    eventBind:function(){
        var fileInput=document.querySelector('input[type=file]'),
            previewImg=$('#prew-img')[0];

        fileInput.addEventListener('change',function(){
            var file=this.files[0];
            var reader=new FileReader();

            var mime_types=['image/png','image/jpeg','image/jpg','image/gif'];
            if($.inArray(file.type,mime_types)===-1){
                alert('请输入png,jpeg,jpg,gif格式图片');
                return false;
            }
            //监听reader对象的onload时间,当图片加载完成,把base64编码赋值给预览图片
            reader.addEventListener('load',function(){
                previewImg.src=reader.result;
            },false);
            //调用reader.readAsDataURL()方法.把图片转成base64
            reader.readAsDataURL(file);
        },false);
    }
};

$(document).ready(function(){
    user_setting_ops.init();
});